<?php
class Api_DbTable_Static extends Core_Db_Table_Abstract implements Core_Db_Crud_Interface
{
    protected $_name = 'statics';

    public function getByUrl($url)
    {
        return $this->fetchRow($this->select()->where('url = ?', $url));
    }

    public function getAll($parent = null)
    {
        return $this->fetchAll($this->select());
    }

    public function getBackUrl($id, $type = 0)
    {
        if ($type === 0)
            return null;
        return Zend_Controller_Front::getInstance()->getRouter()->assemble(array("controller" => "admin", "action" => "read", "name" => "static"), null, true);
    }

    public function getMetaData($id)
    {
        return array('title', 'content', 'url');
    }

    public function getOne($id)
    {
        return $this->fetchRow($this->select()->where('id = ?', $id));
    }

    public function getForm($id, $req = true)
    {
        return new Api_Form_Static ();
    }

    public function create(Zend_Form $form, $parent = 0)
    {
        $data = $form->getValues();
        $data ['url'] = strtolower($data ['url']);
        $this->insert($data);
    }

    public function edit(Zend_Form $form, $id)
    {
        $data = $form->getValues();
        $data ['url'] = strtolower($data ['url']);
        $this->update($data, 'id = ' . $id);
    }

    public function remove($id)
    {
        $this->delete('id = ' . $id);
    }
}